package com.bnlr.lrparking.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bnlr.lrparking.R;
import com.bnlr.lrparking.util.DisplayUtil;
import com.shizhefei.view.indicator.Indicator;

import java.util.List;

/**
 * @author rr
 * @date 2017/5/16
 */

public class HorizontalAdapter extends Indicator.IndicatorAdapter {

    private final List mlist;
    private Context mcontext;
    private LayoutInflater inflater;

    public HorizontalAdapter(Context context, List list) {
        super();
        this.mlist = list;
        this.mcontext = context;
        inflater = LayoutInflater.from(mcontext);
    }

    @Override
    public int getCount() {
        return mlist.size();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.tab_top, parent, false);
        }

        TextView textView = (TextView) convertView;
        //用了固定宽度可以避免TextView文字大小变化，tab宽度变化导致tab抖动现象
        textView.setWidth(DisplayUtil.dipToPix(mcontext, 80));
        textView.setText(mlist.get(position).toString());
        return convertView;
    }
}
